package com.trailer.base.net

import com.trailer.base.base.BApp
import com.trailer.base.utils.Toasts

open class Resp<D>(
        val status: Int = 0,
        val msg: String? = null,
        val total: Int = 0,
        val count: Int = 10,
        val data: D? = null
) : IResp<D> {

    override fun ok(showError: Boolean): Boolean {

        val ok = status == 200

        if(status==500){
            Toasts.toast(BApp.instance(), msg())
        }

//        if (showError && !ok) {
//            Toasts.toast(BApp.instance(), msg())
//        }
        if (showError) {//状态成功的时候也可以提示
            Toasts.toast(BApp.instance(), msg())
        }
//        if(code==0){
//            Toasts.toast(BApp.instance(), msg())
//        }

//        val ok = status == 1
//
////        if (showError && !ok) {
////            Toasts.toast(BApp.instance(), msg())
////        }
//        if (showError) {//状态成功的时候也可以提示
//            Toasts.toast(BApp.instance(), msg())
//        }
        return ok
    }

    override fun code(): Int {
        return status
    }

    override fun count(): Int {
        return count
    }

    override fun total(): Int {
        return total
    }

    override fun msg(): String? {
        return msg
    }

    override fun data(): D? {
        return data
    }

    override fun more(page: Int): Boolean {
        return page * count() < total()
    }

    override fun more(page: Int, pageCount: Int): Boolean {
        return page * count() < total()
    }

    override fun empty(): Boolean {
        return total() <= 0
    }



}
